<template>
  <div class="p-2">
    <!-- 设备二维码管理模块 -->
    <!-- 查询表单 -->
    <el-card shadow="hover" style="margin-bottom: 8px">
      <el-form :model="queryParams" ref="queryFormRef" :inline="true" label-width="68px">
        <el-form-item label="设备名称" prop="deviceName">
          <el-input
            v-model="queryParams.deviceName"
            placeholder="请输入设备名称"
            clearable
            style="width: 200px"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="二维码状态" prop="qrStatus">
          <el-select v-model="queryParams.qrStatus" placeholder="二维码状态" clearable style="width: 150px">
            <el-option label="已生成" value="generated" />
            <el-option label="已绑定" value="bound" />
            <el-option label="已使用" value="used" />
            <el-option label="已过期" value="expired" />
          </el-select>
        </el-form-item>
        <el-form-item label="设备类型" prop="deviceType">
          <el-select v-model="queryParams.deviceType" placeholder="设备类型" clearable style="width: 150px">
            <el-option label="传感器" value="sensor" />
            <el-option label="控制器" value="controller" />
            <el-option label="网关" value="gateway" />
            <el-option label="摄像头" value="camera" />
          </el-select>
        </el-form-item>
        <el-form-item label="创建时间" prop="createTime">
          <el-date-picker
            v-model="queryParams.createTime"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            style="width: 240px"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
          <el-button icon="Refresh" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>

    <!-- 统计卡片 -->
    <el-row :gutter="10" style="margin-bottom: 8px">
      <el-col :span="6">
        <el-card shadow="hover" class="stat-card">
          <div class="stat-item">
            <div class="stat-value">{{ statistics.totalQrCodes }}</div>
            <div class="stat-label">总二维码数</div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card shadow="hover" class="stat-card">
          <div class="stat-item">
            <div class="stat-value generated">{{ statistics.generatedQrCodes }}</div>
            <div class="stat-label">已生成</div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card shadow="hover" class="stat-card">
          <div class="stat-item">
            <div class="stat-value bound">{{ statistics.boundQrCodes }}</div>
            <div class="stat-label">已绑定</div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card shadow="hover" class="stat-card">
          <div class="stat-item">
            <div class="stat-value used">{{ statistics.usedQrCodes }}</div>
            <div class="stat-label">已使用</div>
          </div>
        </el-card>
      </el-col>
    </el-row>

    <!-- 操作按钮 -->
    <el-card shadow="hover" style="margin-bottom: 8px">
      <div class="toolbar">
        <div class="toolbar-left">
          <el-button type="primary" plain icon="Plus" @click="handleAdd">生成二维码</el-button>
          <el-button type="success" plain icon="Upload" @click="handleBatchGenerate">批量生成</el-button>
          <el-button type="warning" plain icon="Download" @click="handleExport">导出二维码</el-button>
          <el-button type="danger" plain icon="Delete" @click="handleBatchDelete" :disabled="!multipleSelection.length">批量删除</el-button>
        </div>
        <div class="toolbar-right">
          <el-button type="info" plain icon="Refresh" @click="handleRefresh">刷新</el-button>
          <el-button type="primary" plain icon="Printer" @click="handleBatchPrint" :disabled="!multipleSelection.length">批量打印</el-button>
        </div>
      </div>
    </el-card>

    <!-- 数据表格 -->
    <el-card shadow="hover">
      <el-table
        v-loading="loading"
        :data="qrCodeList"
        @selection-change="handleSelectionChange"
        style="width: 100%"
      >
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="二维码ID" prop="qrCodeId" width="120" align="center" />
        <el-table-column label="设备名称" prop="deviceName" width="180" show-overflow-tooltip>
          <template #default="scope">
            <el-link type="primary" @click="handleView(scope.row)">{{ scope.row.deviceName }}</el-link>
          </template>
        </el-table-column>
        <el-table-column label="设备类型" prop="deviceType" width="120" align="center">
          <template #default="scope">
            <el-tag :type="getDeviceTypeTagType(scope.row.deviceType)">{{ getDeviceTypeText(scope.row.deviceType) }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="二维码" prop="qrCode" width="120" align="center">
          <template #default="scope">
            <el-button type="primary" plain size="small" @click="handlePreviewQrCode(scope.row)">预览</el-button>
          </template>
        </el-table-column>
        <el-table-column label="状态" prop="qrStatus" width="100" align="center">
          <template #default="scope">
            <el-tag :type="getStatusTagType(scope.row.qrStatus)">{{ getStatusText(scope.row.qrStatus) }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="绑定设备ID" prop="boundDeviceId" width="140" align="center">
          <template #default="scope">
            <span v-if="scope.row.boundDeviceId">{{ scope.row.boundDeviceId }}</span>
            <span v-else class="text-gray-400">未绑定</span>
          </template>
        </el-table-column>
        <el-table-column label="有效期" prop="expiryDate" width="120" align="center">
          <template #default="scope">
            <span :class="{ 'text-red-500': isExpired(scope.row.expiryDate) }">
              {{ scope.row.expiryDate }}
            </span>
          </template>
        </el-table-column>
        <el-table-column label="使用次数" prop="usageCount" width="100" align="center" />
        <el-table-column label="创建人" prop="creator" width="120" align="center" />
        <el-table-column label="创建时间" prop="createTime" width="160" align="center" />
        <el-table-column label="操作" width="280" align="center" fixed="right">
          <template #default="scope">
            <el-button type="primary" plain size="small" icon="View" @click="handleView(scope.row)">详情</el-button>
            <el-button type="success" plain size="small" icon="Download" @click="handleDownload(scope.row)">下载</el-button>
            <el-button type="warning" plain size="small" icon="Printer" @click="handlePrint(scope.row)">打印</el-button>
            <el-button type="danger" plain size="small" icon="Delete" @click="handleDelete(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页 -->
      <div class="pagination-container">
        <el-pagination
          v-model:current-page="queryParams.pageNum"
          v-model:page-size="queryParams.pageSize"
          :total="total"
          :page-sizes="[10, 20, 50, 100]"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </el-card>

    <!-- 生成二维码对话框 -->
    <el-dialog :title="dialog.title" v-model="dialog.visible" width="600px" append-to-body>
      <el-form :model="form" :rules="rules" ref="formRef" label-width="100px">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="设备名称" prop="deviceName">
              <el-input v-model="form.deviceName" placeholder="请输入设备名称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="设备类型" prop="deviceType">
              <el-select v-model="form.deviceType" placeholder="请选择设备类型" style="width: 100%">
                <el-option label="传感器" value="sensor" />
                <el-option label="控制器" value="controller" />
                <el-option label="网关" value="gateway" />
                <el-option label="摄像头" value="camera" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="设备型号" prop="deviceModel">
              <el-input v-model="form.deviceModel" placeholder="请输入设备型号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="设备序列号" prop="serialNumber">
              <el-input v-model="form.serialNumber" placeholder="请输入设备序列号" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="有效期" prop="expiryDate">
              <el-date-picker
                v-model="form.expiryDate"
                type="date"
                placeholder="选择有效期"
                style="width: 100%"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="最大使用次数" prop="maxUsage">
              <el-input-number v-model="form.maxUsage" :min="1" :max="1000" style="width: 100%" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="二维码内容" prop="qrContent">
          <el-input v-model="form.qrContent" type="textarea" :rows="3" placeholder="请输入二维码内容（JSON格式）" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" :rows="2" placeholder="请输入备注信息" />
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="dialog.visible = false">取消</el-button>
          <el-button type="primary" @click="handleSubmit">确定</el-button>
        </div>
      </template>
    </el-dialog>

    <!-- 二维码详情对话框 -->
    <el-dialog title="二维码详情" v-model="detailDialog.visible" width="800px" append-to-body>
      <el-descriptions :column="2" border>
        <el-descriptions-item label="二维码ID">{{ detailData.qrCodeId }}</el-descriptions-item>
        <el-descriptions-item label="设备名称">{{ detailData.deviceName }}</el-descriptions-item>
        <el-descriptions-item label="设备类型">
          <el-tag :type="getDeviceTypeTagType(detailData.deviceType)">{{ getDeviceTypeText(detailData.deviceType) }}</el-tag>
        </el-descriptions-item>
        <el-descriptions-item label="设备型号">{{ detailData.deviceModel }}</el-descriptions-item>
        <el-descriptions-item label="设备序列号">{{ detailData.serialNumber }}</el-descriptions-item>
        <el-descriptions-item label="状态">
          <el-tag :type="getStatusTagType(detailData.qrStatus)">{{ getStatusText(detailData.qrStatus) }}</el-tag>
        </el-descriptions-item>
        <el-descriptions-item label="绑定设备ID">{{ detailData.boundDeviceId || '未绑定' }}</el-descriptions-item>
        <el-descriptions-item label="有效期">{{ detailData.expiryDate }}</el-descriptions-item>
        <el-descriptions-item label="使用次数">{{ detailData.usageCount }}/{{ detailData.maxUsage }}</el-descriptions-item>
        <el-descriptions-item label="创建人">{{ detailData.creator }}</el-descriptions-item>
        <el-descriptions-item label="创建时间">{{ detailData.createTime }}</el-descriptions-item>
        <el-descriptions-item label="最后使用时间">{{ detailData.lastUsedTime || '未使用' }}</el-descriptions-item>
        <el-descriptions-item label="备注" :span="2">{{ detailData.remark }}</el-descriptions-item>
      </el-descriptions>
      
      <el-divider>二维码内容</el-divider>
      <el-input v-model="detailData.qrContent" type="textarea" :rows="4" readonly />
      
      <el-divider>使用记录</el-divider>
      <el-table :data="usageHistory" style="width: 100%" max-height="300">
        <el-table-column label="使用时间" prop="usageTime" width="160" />
        <el-table-column label="使用设备" prop="deviceId" width="120" />
        <el-table-column label="操作类型" prop="operationType" width="100" />
        <el-table-column label="IP地址" prop="ipAddress" width="120" />
        <el-table-column label="用户" prop="user" width="100" />
        <el-table-column label="结果" prop="result" width="80">
          <template #default="scope">
            <el-tag :type="scope.row.result === 'success' ? 'success' : 'danger'">
              {{ scope.row.result === 'success' ? '成功' : '失败' }}
            </el-tag>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>

    <!-- 二维码预览对话框 -->
    <el-dialog title="二维码预览" v-model="previewDialog.visible" width="400px" append-to-body>
      <div class="qr-preview">
        <div class="qr-code-container">
          <!-- 这里应该是实际的二维码图片 -->
          <div class="qr-code-placeholder">
            <el-icon size="80"><Grid /></el-icon>
            <p>{{ previewData.deviceName }}</p>
            <p class="qr-id">{{ previewData.qrCodeId }}</p>
          </div>
        </div>
        <div class="qr-info">
          <p><strong>设备名称：</strong>{{ previewData.deviceName }}</p>
          <p><strong>设备类型：</strong>{{ getDeviceTypeText(previewData.deviceType) }}</p>
          <p><strong>有效期：</strong>{{ previewData.expiryDate }}</p>
          <p><strong>状态：</strong>{{ getStatusText(previewData.qrStatus) }}</p>
        </div>
      </div>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="previewDialog.visible = false">关闭</el-button>
          <el-button type="primary" @click="handleDownload(previewData)">下载</el-button>
          <el-button type="success" @click="handlePrint(previewData)">打印</el-button>
        </div>
      </template>
    </el-dialog>

    <!-- 批量生成对话框 -->
    <el-dialog title="批量生成二维码" v-model="batchDialog.visible" width="600px" append-to-body>
      <el-form :model="batchForm" :rules="batchRules" ref="batchFormRef" label-width="120px">
        <el-form-item label="生成数量" prop="quantity">
          <el-input-number v-model="batchForm.quantity" :min="1" :max="1000" style="width: 200px" />
        </el-form-item>
        <el-form-item label="设备类型" prop="deviceType">
          <el-select v-model="batchForm.deviceType" placeholder="请选择设备类型" style="width: 200px">
            <el-option label="传感器" value="sensor" />
            <el-option label="控制器" value="controller" />
            <el-option label="网关" value="gateway" />
            <el-option label="摄像头" value="camera" />
          </el-select>
        </el-form-item>
        <el-form-item label="设备名称前缀" prop="namePrefix">
          <el-input v-model="batchForm.namePrefix" placeholder="请输入设备名称前缀" style="width: 200px" />
        </el-form-item>
        <el-form-item label="有效期" prop="expiryDate">
          <el-date-picker
            v-model="batchForm.expiryDate"
            type="date"
            placeholder="选择有效期"
            style="width: 200px"
          />
        </el-form-item>
        <el-form-item label="最大使用次数" prop="maxUsage">
          <el-input-number v-model="batchForm.maxUsage" :min="1" :max="1000" style="width: 200px" />
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="batchDialog.visible = false">取消</el-button>
          <el-button type="primary" @click="handleBatchSubmit">生成</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="QrcodeManage" lang="ts">
import { ref, reactive, onMounted } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { Search, Refresh, Plus, Upload, Download, Delete, View, Edit, Printer, Grid } from '@element-plus/icons-vue'

// 响应式数据
const loading = ref(false)
const total = ref(0)
const multipleSelection = ref([])

// 查询参数
const queryParams = reactive({
  pageNum: 1,
  pageSize: 10,
  deviceName: '',
  qrStatus: '',
  deviceType: '',
  createTime: null
})

// 统计数据
const statistics = reactive({
  totalQrCodes: 1256,
  generatedQrCodes: 856,
  boundQrCodes: 324,
  usedQrCodes: 76
})

// 二维码列表
const qrCodeList = ref([
  {
    qrCodeId: 'QR001',
    deviceName: '温度传感器01',
    deviceType: 'sensor',
    deviceModel: 'TH-2000',
    serialNumber: 'SN20240115001',
    qrStatus: 'bound',
    boundDeviceId: 'DEV001',
    expiryDate: '2024-12-31',
    usageCount: 3,
    maxUsage: 10,
    creator: '张三',
    createTime: '2024-01-15 09:30:00',
    lastUsedTime: '2024-01-15 14:20:30',
    qrContent: '{"deviceId":"DEV001","deviceType":"sensor","model":"TH-2000"}',
    remark: '车间温度监控传感器'
  },
  {
    qrCodeId: 'QR002',
    deviceName: '智能开关02',
    deviceType: 'controller',
    deviceModel: 'SW-3000',
    serialNumber: 'SN20240115002',
    qrStatus: 'generated',
    boundDeviceId: '',
    expiryDate: '2024-11-30',
    usageCount: 0,
    maxUsage: 5,
    creator: '李四',
    createTime: '2024-01-15 10:15:00',
    lastUsedTime: '',
    qrContent: '{"deviceType":"controller","model":"SW-3000","serialNumber":"SN20240115002"}',
    remark: '办公室照明控制开关'
  },
  {
    qrCodeId: 'QR003',
    deviceName: '边缘网关03',
    deviceType: 'gateway',
    deviceModel: 'GW-5000',
    serialNumber: 'SN20240115003',
    qrStatus: 'used',
    boundDeviceId: 'GW003',
    expiryDate: '2025-01-31',
    usageCount: 5,
    maxUsage: 5,
    creator: '王五',
    createTime: '2024-01-15 11:00:00',
    lastUsedTime: '2024-01-15 13:45:15',
    qrContent: '{"deviceId":"GW003","deviceType":"gateway","model":"GW-5000"}',
    remark: '生产线数据采集网关'
  },
  {
    qrCodeId: 'QR004',
    deviceName: '监控摄像头04',
    deviceType: 'camera',
    deviceModel: 'CAM-8000',
    serialNumber: 'SN20240115004',
    qrStatus: 'expired',
    boundDeviceId: '',
    expiryDate: '2024-01-10',
    usageCount: 0,
    maxUsage: 3,
    creator: '赵六',
    createTime: '2024-01-05 14:20:00',
    lastUsedTime: '',
    qrContent: '{"deviceType":"camera","model":"CAM-8000","serialNumber":"SN20240115004"}',
    remark: '仓库安防监控摄像头'
  },
  {
    qrCodeId: 'QR005',
    deviceName: '湿度传感器05',
    deviceType: 'sensor',
    deviceModel: 'HU-1500',
    serialNumber: 'SN20240115005',
    qrStatus: 'bound',
    boundDeviceId: 'DEV005',
    expiryDate: '2024-10-31',
    usageCount: 1,
    maxUsage: 8,
    creator: '孙七',
    createTime: '2024-01-15 15:45:00',
    lastUsedTime: '2024-01-15 16:10:20',
    qrContent: '{"deviceId":"DEV005","deviceType":"sensor","model":"HU-1500"}',
    remark: '温室环境湿度监测'
  }
])

// 使用记录
const usageHistory = ref([
  {
    usageTime: '2024-01-15 14:20:30',
    deviceId: 'DEV001',
    operationType: '绑定',
    ipAddress: '192.168.1.100',
    user: '张三',
    result: 'success'
  },
  {
    usageTime: '2024-01-15 12:15:20',
    deviceId: 'DEV001',
    operationType: '扫描',
    ipAddress: '192.168.1.101',
    user: '李四',
    result: 'success'
  },
  {
    usageTime: '2024-01-15 10:30:15',
    deviceId: 'DEV001',
    operationType: '验证',
    ipAddress: '192.168.1.102',
    user: '王五',
    result: 'failed'
  }
])

// 对话框状态
const dialog = reactive({
  visible: false,
  title: ''
})

const detailDialog = reactive({
  visible: false
})

const previewDialog = reactive({
  visible: false
})

const batchDialog = reactive({
  visible: false
})

// 表单数据
const form = reactive({
  qrCodeId: '',
  deviceName: '',
  deviceType: '',
  deviceModel: '',
  serialNumber: '',
  expiryDate: '',
  maxUsage: 10,
  qrContent: '',
  remark: ''
})

// 批量生成表单
const batchForm = reactive({
  quantity: 10,
  deviceType: '',
  namePrefix: '',
  expiryDate: '',
  maxUsage: 10
})

// 详情数据
const detailData = reactive({})

// 预览数据
const previewData = reactive({})

// 表单验证规则
const rules = {
  deviceName: [{ required: true, message: '请输入设备名称', trigger: 'blur' }],
  deviceType: [{ required: true, message: '请选择设备类型', trigger: 'change' }],
  deviceModel: [{ required: true, message: '请输入设备型号', trigger: 'blur' }],
  serialNumber: [{ required: true, message: '请输入设备序列号', trigger: 'blur' }],
  expiryDate: [{ required: true, message: '请选择有效期', trigger: 'change' }],
  maxUsage: [{ required: true, message: '请输入最大使用次数', trigger: 'blur' }]
}

// 批量生成验证规则
const batchRules = {
  quantity: [{ required: true, message: '请输入生成数量', trigger: 'blur' }],
  deviceType: [{ required: true, message: '请选择设备类型', trigger: 'change' }],
  namePrefix: [{ required: true, message: '请输入设备名称前缀', trigger: 'blur' }],
  expiryDate: [{ required: true, message: '请选择有效期', trigger: 'change' }],
  maxUsage: [{ required: true, message: '请输入最大使用次数', trigger: 'blur' }]
}

// 获取设备类型标签类型
const getDeviceTypeTagType = (type: string) => {
  const typeMap = {
    sensor: 'primary',
    controller: 'success',
    gateway: 'warning',
    camera: 'info'
  }
  return typeMap[type] || 'info'
}

// 获取设备类型文本
const getDeviceTypeText = (type: string) => {
  const typeMap = {
    sensor: '传感器',
    controller: '控制器',
    gateway: '网关',
    camera: '摄像头'
  }
  return typeMap[type] || type
}

// 获取状态标签类型
const getStatusTagType = (status: string) => {
  const statusMap = {
    generated: 'info',
    bound: 'success',
    used: 'warning',
    expired: 'danger'
  }
  return statusMap[status] || 'info'
}

// 获取状态文本
const getStatusText = (status: string) => {
  const statusMap = {
    generated: '已生成',
    bound: '已绑定',
    used: '已使用',
    expired: '已过期'
  }
  return statusMap[status] || status
}

// 判断是否过期
const isExpired = (expiryDate: string) => {
  return new Date(expiryDate) < new Date()
}

// 查询
const handleQuery = () => {
  loading.value = true
  // 模拟API调用
  setTimeout(() => {
    loading.value = false
  }, 1000)
}

// 重置查询
const resetQuery = () => {
  Object.assign(queryParams, {
    pageNum: 1,
    pageSize: 10,
    deviceName: '',
    qrStatus: '',
    deviceType: '',
    createTime: null
  })
  handleQuery()
}

// 新增
const handleAdd = () => {
  dialog.title = '生成二维码'
  dialog.visible = true
  Object.assign(form, {
    qrCodeId: '',
    deviceName: '',
    deviceType: '',
    deviceModel: '',
    serialNumber: '',
    expiryDate: '',
    maxUsage: 10,
    qrContent: '',
    remark: ''
  })
}

// 查看详情
const handleView = (row: any) => {
  Object.assign(detailData, row)
  detailDialog.visible = true
}

// 预览二维码
const handlePreviewQrCode = (row: any) => {
  Object.assign(previewData, row)
  previewDialog.visible = true
}

// 下载二维码
const handleDownload = (row: any) => {
  ElMessage.success(`正在下载二维码：${row.deviceName}`)
}

// 打印二维码
const handlePrint = (row: any) => {
  ElMessage.success(`正在打印二维码：${row.deviceName}`)
}

// 删除
const handleDelete = (row: any) => {
  ElMessageBox.confirm(`确认删除二维码"${row.deviceName}"？`, '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  }).then(() => {
    ElMessage.success('删除成功')
    handleQuery()
  })
}

// 批量删除
const handleBatchDelete = () => {
  ElMessageBox.confirm('确认删除选中的二维码？', '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  }).then(() => {
    ElMessage.success('批量删除成功')
    handleQuery()
  })
}

// 批量生成
const handleBatchGenerate = () => {
  batchDialog.visible = true
  Object.assign(batchForm, {
    quantity: 10,
    deviceType: '',
    namePrefix: '',
    expiryDate: '',
    maxUsage: 10
  })
}

// 导出
const handleExport = () => {
  ElMessage.info('导出功能开发中')
}

// 刷新
const handleRefresh = () => {
  handleQuery()
}

// 批量打印
const handleBatchPrint = () => {
  ElMessage.success(`正在批量打印${multipleSelection.value.length}个二维码`)
}

// 提交表单
const handleSubmit = () => {
  ElMessage.success('二维码生成成功')
  dialog.visible = false
  handleQuery()
}

// 批量生成提交
const handleBatchSubmit = () => {
  ElMessage.success(`批量生成${batchForm.quantity}个二维码成功`)
  batchDialog.visible = false
  handleQuery()
}

// 选择变更
const handleSelectionChange = (selection: any[]) => {
  multipleSelection.value = selection
}

// 分页大小变更
const handleSizeChange = (size: number) => {
  queryParams.pageSize = size
  handleQuery()
}

// 当前页变更
const handleCurrentChange = (page: number) => {
  queryParams.pageNum = page
  handleQuery()
}

// 组件挂载
onMounted(() => {
  handleQuery()
})
</script>

<style scoped>
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
}

.toolbar-left,
.toolbar-right {
  display: flex;
  gap: 10px;
}

.stat-card {
  text-align: center;
}

.stat-item {
  padding: 20px;
}

.stat-value {
  font-size: 28px;
  font-weight: bold;
  color: #303133;
  margin-bottom: 8px;
}

.stat-value.generated {
  color: #409eff;
}

.stat-value.bound {
  color: #67c23a;
}

.stat-value.used {
  color: #e6a23c;
}

.stat-label {
  font-size: 14px;
  color: #909399;
}

.pagination-container {
  display: flex;
  justify-content: center;
  margin-top: 20px;
}

.qr-preview {
  text-align: center;
}

.qr-code-container {
  margin-bottom: 20px;
}

.qr-code-placeholder {
  border: 2px dashed #dcdfe6;
  border-radius: 8px;
  padding: 40px;
  background-color: #fafafa;
}

.qr-code-placeholder .el-icon {
  color: #c0c4cc;
  margin-bottom: 10px;
}

.qr-code-placeholder p {
  margin: 5px 0;
  color: #606266;
}

.qr-id {
  font-size: 12px;
  color: #909399;
}

.qr-info {
  text-align: left;
  background-color: #f5f7fa;
  padding: 15px;
  border-radius: 4px;
}

.qr-info p {
  margin: 8px 0;
  color: #606266;
}

.text-gray-400 {
  color: #c0c4cc;
}

.text-red-500 {
  color: #f56c6c;
}
</style>